package cn.hly.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import cn.hly.master.pojo.PubdleCase000Info;
import cn.hly.master.pojo.UrpUser;
import cn.hly.service.TestService;
import cn.hly.slave.dao.HeroDao;
import cn.hly.slave.pojo.Hero;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/test")
public class TestController {
	
	@Autowired
	private TestService testService;
	@Autowired
	private HeroDao heroDao;
	static final Logger logger = LoggerFactory.getLogger(TestController.class);

	/**
	 *  查找所有英雄
	 * @return
	 */
	@RequestMapping(value = "/getAllHero",method = RequestMethod.GET)
	public List<Hero> getAllHero(){
		logger.info("德玛西亚");
		logger.error("诺克萨斯");
		return heroDao.getAllHero();


	}


	/**
	 *
	 * @return
	 */
	@RequestMapping("/insert")
	public JSONObject insert(){
		UrpUser user=new UrpUser();
		user.setId(UUID.randomUUID().toString().replace("-",""));
		user.setCreatetime(System.currentTimeMillis());
		Hero hero=new Hero();
		hero.setHeroCode("213");
		hero.setHeroName("诺克萨斯");
		return testService.save(user,hero);
	}

	/**
	 *
	 * @return
	 */
	@RequestMapping("/caseList")
	public JSONObject caseList(HttpServletRequest request) {
		String code=request.getParameter("code");
		String addr=request.getParameter("addr");
		Map<String,Object> map=new HashMap<>();
		PubdleCase000Info case000Info=new PubdleCase000Info();

		if(StringUtils.isNotBlank(code)){
			case000Info.setcCode(code);
			map.put("cCode",code);
		}

		if(StringUtils.isNotBlank(addr)){
			case000Info.setcOccuraddr(addr);
			map.put("cOccuraddr",addr);
		}
		PageInfo<Map<String,Object>> pageInfo= testService.selectPage(1, 10, map);
		PageInfo<PubdleCase000Info> pageInfo2=testService.selectCasePage(1, 10, case000Info);

		JSONObject jsonObject=new JSONObject();
		jsonObject.put("11",pageInfo);
		jsonObject.put("22",pageInfo2);
		return jsonObject;
	}

	/**
	 *
	 * @return
	 */
	@GetMapping("/operate")
	public JSONObject operate(){


		String sql="select t1.cardnum,t2.c_code from urp_user t1,pubdle_case000_info t2 where   t1.id=t2.c_undertakerAId ";

		return testService.operate(1,10,sql);


	}




}
